package 工具.动态链表生成;

import 工具.单向节点.Node;

import java.util.HashMap;

/**
 * 动态生成链表
 */
public class DynamicListUtil {
    public static Node createDynamicList(int[] array) {
        HashMap<Integer, Node> map = new HashMap<>();
        for (int i = 0; i < array.length; ++i) {
            map.put(i, new Node(array[i]));
        }

        for (Integer key : map.keySet()) {
            if (key == (array.length - 1)) {
                break;
            }
            map.get(key).setNext(map.get(key + 1));

        }

        return map.get(0);
    }
}
